import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import useProTableConfig from '../../hooks/useProTableConfig';
import styles from './index.less';
// import type { FileRuleOTD } from '@/services/types/rulesCenter/modelManagement';
import { openEnum, sensitiveEnum } from '@/enum';
import { FileAddFilled } from '@ant-design/icons';
import { Button, Popconfirm, Space } from 'antd';
import { useEffect } from 'react';
import { useModel } from 'umi';
import hooks from '../../hooks';
export default () => {
  const {
    formRef,

    tabsType,
    tabKey,

    getData,
    setKeyWord,
    setResourceKnowledgeData,
    setModalKnowledgeVisible,
    drawerDetailToggle,
    knowledgeDrawerDetailToggle,
    setDsCode,
    editKnowledgeContent,
  } = hooks.useContainer();
  const proTableConfig = useProTableConfig({
    optionRender(config, props, dom) {
      return [...dom.reverse()];
    },
  });

  const { actionRef } = useModel('useTree', (model) => {
    return {
      actionRef: model.actionRef,
    };
  });

  useEffect(() => {
    return () => {
      setKeyWord('');
    };
  }, []);

  const columns: ProColumns<any>[] = [
    {
      dataIndex: 'index',
      valueType: 'indexBorder',
      width: 48,
      title: '序号',
    },
    {
      title: '知识库名称',
      dataIndex: 'name',
      ellipsis: true,
    },
    {
      title: '是否高质量数据集',
      dataIndex: 'isHeightQuality',
      ellipsis: true,
      width: 146,
      renderText: (_, record) => {
        return <>{record.isHeightQuality ? '是' : '否'}</>;
      },
    },

    {
      title: '知识库类型',
      dataIndex: 'type',
      ellipsis: true,
      hideInSearch: true,
      renderText: (_, record) => {
        return (
          <>
            {record.type === 'bm'
              ? '部门'
              : record.type === 'gg'
              ? '公共'
              : record.type === 'gr'
              ? '个人'
              : ''}
          </>
        );
      },
    },
    {
      title: '公开属性',
      dataIndex: 'openProperty',

      width: 126,
      hideInSearch: true,
      renderText: (_, record) => {
        return <>{openEnum[record.openProperty + '']}</>;
      },
    },
    {
      title: '敏感等级',
      width: 126,
      dataIndex: 'sensitiveLevel',
      hideInSearch: true,
      renderText: (_, record) => {
        return <>{sensitiveEnum[record.sensitiveLevel + '']}</>;
      },
    },
    {
      title: '状态',
      dataIndex: 'status',
      width: 62,
      hideInSearch: true,
      renderText: (_, record) => {
        return <>{record.status === 0 ? '禁用' : '已启用'}</>;
      },
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '创建人',
      dataIndex: 'createUserName',
      ellipsis: true,
      hideInSearch: true,
      width: 100,
    },

    {
      title: '更新时间',
      dataIndex: 'updateTime',
      hideInSearch: true,
      ellipsis: true,
    },
    {
      title: '描述',
      dataIndex: 'knowledgeDescribe',
      width: 160,
      ellipsis: true,
      hideInSearch: true,
    },

    {
      title: '操作',
      width: 126,
      dataIndex: 'operate',
      hideInSearch: true,
      renderText: (text, record) => {
        return (
          <Space size="small" className={styles.spaceWrap}>
            <a
              onClick={() => {
                setDsCode(record.bailianKnowledgeId);
                drawerDetailToggle();
              }}
            >
              详情
            </a>
            {/* <a
              onClick={() => {
                setDsCode(record.bailianKnowledgeId);
                knowledgeDrawerDetailToggle()
              }}
            >
              知识库内容
            </a> */}
            <a
              onClick={() => {
                setResourceKnowledgeData({ ...record });
                setModalKnowledgeVisible(true);
              }}
            >
              修改
            </a>
            <Popconfirm
              key="delete"
              title="确认是禁用当前知识？"
              onConfirm={() => {
                editKnowledgeContent.run({ ...record, status: record.status === 1 ? 0 : 1 });
              }}
            >
              <a style={{ color: '#f02323' }}>{record.status === 1 ? '禁用' : '启用'}</a>
            </Popconfirm>
          </Space>
        );
      },
    },
  ];
  return (
    <ProTable
      {...proTableConfig}
      className={styles.resourceTableWrap}
      actionRef={actionRef}
      formRef={formRef}
      columns={columns}
      request={getData.runAsync}
      size="middle"
      rowKey="id"
      ghost={true}
      search={false}
      // options={{
      //   search: true,
      // }}
      toolbar={{
        actions: [
          <Button
            key="create"
            icon={<FileAddFilled />}
            type="primary"
            onClick={() => {
              setModalKnowledgeVisible(true);
            }}
          >
            {`创建${tabsType[tabKey].name}`}
          </Button>,
        ],
        search: {
          style: {
            width: '300px',
          },
          placeholder: '请输入内容',
          onSearch: (arg) => {
            console.log(arg);
            setKeyWord(arg);
            actionRef.current?.reload();
          },
        },
      }}
    />
  );
};
